//
//  ZqlMainTabar.swift
//  ZqlSinaWeiBo
//
//  Created by 赵乾龙 on 16/2/16.
//  Copyright © 2016年 Mr.zhao. All rights reserved.
//

import UIKit

class ZqlMainTabar: UITabBar {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(plusBtn)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //布局子视图
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //设置tabBar的尺寸
        let w=self.bounds.width/5
        let h=self.bounds.height
        let rect=CGRect(x: 0, y: 0, width: w, height: h)
        
        var index:CGFloat = 0
        
        for subView in subviews{
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){
                subView.frame=CGRectOffset(rect, w * index, 0)
                index += (index == 1 ? 2 : 1)
            }
        }
        //设置加号按钮的位置
        plusBtn.frame = CGRectOffset(rect, 2 * w, 0)
    }
    
    //通过懒加载创建button
    lazy var plusBtn: UIButton = UIButton(backImageName: "tabbar_compose_button", imageName: "tabbar_compose_icon_add")
    
}




